package com.evildog.workspace.life.application.controller;

import com.evildog.workspace.common.object.PageQuery;
import com.evildog.workspace.common.result.PagedResult;
import com.evildog.workspace.common.result.Result;
import com.evildog.workspace.common.result.ResultGenerator;
import com.evildog.workspace.dependencies.mybatis.util.QueryConditionUtils;
import com.evildog.workspace.life.application.bo.AlbumCategoryBO;
import com.evildog.workspace.life.application.bo.AlbumCategoryPageBO;
import com.evildog.workspace.life.application.convert.AlbumCategoryConvert;
import com.evildog.workspace.life.application.model.AlbumCategoryPageParam;
import com.evildog.workspace.life.application.model.AlbumCategoryParam;
import com.evildog.workspace.life.application.service.AlbumCategoryService;
import com.evildog.workspace.life.application.vo.AlbumCategoryPageVO;
import com.evildog.workspace.life.application.vo.AlbumCategoryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * albumCategory Controller
    相册分类（精选）
 * </p>
 *
 * @author evildog
 * @since 2020-07-18
 */
@RestController
@RequestMapping("/album-categories")
@AllArgsConstructor
@Api(tags = "albumCategory相关接口")
public class AlbumCategoryController {
    private AlbumCategoryService albumCategoryService;

    @PostMapping
    @ApiOperation(value = "添加接口")
    public Result<Boolean> save(@RequestBody AlbumCategoryParam albumCategoryParam) {
        return ResultGenerator.status(albumCategoryService.save(AlbumCategoryConvert.INSTANCE.convert(albumCategoryParam)));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除接口")
    public Result<Boolean> removeById(@PathVariable("id") Long id) {
        return ResultGenerator.status(albumCategoryService.removeById(id));
    }

    @PutMapping("/{id}")
    @ApiOperation(value = "更新接口")
    public Result<Boolean> updateById(@PathVariable("id") Long id,@RequestBody AlbumCategoryParam albumCategoryParam) {
        return ResultGenerator.status(albumCategoryService.updateById(id, AlbumCategoryConvert.INSTANCE.convert(albumCategoryParam)));
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "查询详情接口")
    public Result<AlbumCategoryVO> getById(@PathVariable("id") Long id) {
        AlbumCategoryBO albumCategoryBO = albumCategoryService.getDetailById(id);
        return ResultGenerator.success(AlbumCategoryConvert.INSTANCE.convert(albumCategoryBO));
    }

    @GetMapping("/page")
    @ApiOperation(value = "表分页查询接口")
    public Result<PagedResult<AlbumCategoryPageVO>> getPageList(AlbumCategoryPageParam albumCategoryPageParam,PageQuery query){
        PagedResult<AlbumCategoryPageBO> albumCategoryPageBO = albumCategoryService.getPageList(
                        query,
                        QueryConditionUtils.getQueryCondition(albumCategoryPageParam),
                        AlbumCategoryConvert.INSTANCE.convert(albumCategoryPageParam));
        return ResultGenerator.success(AlbumCategoryConvert.INSTANCE.convert(albumCategoryPageBO));
    }

}
